<template>
  <el-radio-group v-model="selectvalue" @change="changeParent">
    <el-radio v-for="item in options" :key="item.code" :label="item.name" text="item.name">{{ item.name }}</el-radio>
  </el-radio-group>

</template>

<script>
  import {
    getListDefaults
  } from '@/api/adminPage/attributeDefinition/materials'
  export default {
    props: {
      dictType: {
        type: String
      },
      value: {
        type: String
      },
      sysType: {
        type: String // tenant代表租户，其他代表平台，默认租户
      }
    },
    data() {
      return {
        options: [],
        selectvalue: '',
        multiples: false,
        optionMap: new Map()
      }
    },
    watch: {
      value: function(newVal) {
        this.selectvalue = newVal
      },
      selectvalue: function(newVal, oldVal) {
        if (newVal !== oldVal) {
          this.$emit('input', newVal)
        }
      }
    },
    created() {
      // 获取字典值
      const query = {
        code: this.dictType
      }
      const that = this
      getListDefaults(query).then(response => {
        that.options = response.result
        // 初始化map对象
        that.options.forEach(row => {
          const obj = {}
          obj.lable = row.name
          obj.value = row.code
          this.optionMap.set(row.dictValue, obj)
        })
      })
      this.selectvalue = this.value
    },
    methods: {
      changeParent() {
        const changevalue = this.selectvalue
        const array = []
        array.push(this.optionMap.get(changevalue))
        this.$emit('selected', array)
      }
    }
  }
</script>

<style>
</style>
